package com.team233.zuccecho.repository;

import com.team233.zuccecho.Bean.Clazz;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface ClazzRepository extends JpaRepository<Clazz,Integer> {
    @Query(value="select * from clazz where clazz_name=?1",nativeQuery = true)
    Clazz findByName(String name);

    @Query(value="select * from clazz where clazz_id=?1",nativeQuery = true)
    Clazz findById(long clazz_id);

    @Query(value="select * from clazz where teacher_id=?1",nativeQuery = true)
    List<Clazz> findByTeaId(String tea_id);

    @Query(value="select clazz_id from stu_clazz where student_id=?1",nativeQuery = true)
    List<Long> findByStuId(long stu_id);

    @Transactional
    @Modifying
    @Query(value="update clazz set teacher_teacher_id=?1 where clazz_id=?2",nativeQuery = true)
    void modifyTea(String tea_id,long clazz_id);
}
